/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.domain;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.joda.time.LocalDate;

/**
 *
 * @author Martin Řehánek (rehan@mzk.cz)
 */
public class Issue {

    private final int number;
    private final LocalDate date;
    private final DayTime dayTime;
    private final boolean forChildren;
    private int stars;

    public static Issue instanceOf(Integer number, LocalDate date, DayTime dayTime, boolean forChildren, Integer stars) {
        if (number == null) {
            Logger.getLogger(Issue.class.getName()).log(Level.WARNING, "number == null");
            return null;
        }
        if (number < 0) {
            Logger.getLogger(Issue.class.getName()).log(Level.WARNING, "number < 0");
            return null;
        }
        if (date == null) {
            Logger.getLogger(Issue.class.getName()).log(Level.WARNING, "date == null");
            return null;
        }
        if (dayTime == null) {
            Logger.getLogger(Issue.class.getName()).log(Level.WARNING, "dayTime == null");
            return null;
        }
        if (stars == null) {
            Logger.getLogger(Issue.class.getName()).log(Level.WARNING, "stars == null");
            return null;
        }
        return new Issue(number, date, dayTime, forChildren, stars);
    }

    private Issue(int number, LocalDate date, DayTime dayTime, boolean forChildren, int stars) {
        this.number = number;
        this.date = date;
        this.dayTime = dayTime;
        this.forChildren = forChildren;
        this.stars = stars;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(date.toString());
        builder.append(',').append(number);
        builder.append(',').append(dayTime);
        builder.append(",dětské:").append(forChildren);
        builder.append(",stars:").append(stars);
        return builder.toString();
    }

    @Override
    public boolean equals(Object obj) {
//        System.out.println("prvni " + this.toString() + "   " + obj.toString());
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Issue other = (Issue) obj;
        if (this.number != other.number) {
            return false;
        }
        if (this.date != other.date && (this.date == null || !this.date.equals(other.date))) {
            return false;
        }
        if (this.dayTime != other.dayTime) {
            return false;
        }
        if (this.forChildren != other.isForChildren()) {
            return false;
        }
        if (this.stars != other.getStars()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + this.number;
        hash = 47 * hash + (this.date != null ? this.date.hashCode() : 0);
        hash = 47 * hash + (this.dayTime != null ? this.dayTime.hashCode() : 0);
        hash = 47 * hash + (this.forChildren ? 1 : 0);
        hash = 47 * hash + this.stars;
        return hash;
    }

    /**
     * @return the number
     */
    public int getNumber() {
        return number;
    }

    /**
     * @return the date
     */
    public LocalDate getDate() {
        return date;
    }

    /**
     * @return the dayTime
     */
    public DayTime getDayTime() {
        return dayTime;
    }

    public boolean isForChildren() {
        return forChildren;
    }

    public int getStars() {
        return stars;
    }

    public void setStars(int stars) {
        this.stars = stars;
    }
}
